<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
            onload = () => {
                setInterval("time()", 1);
            };
            //拼接指定格式的字符
            function time() {
                let div = document.getElementById("time");
                div.style.width="550px";
                div.style.margin="auto";
                div.style.border="1px solid black";
                //创一个日期对象
                let date = new Date();
                let year = date.getFullYear();
                let month = date.getMonth() + 1;
                let monthDay = date.getDate();
                let weekDay = date.getDay();
                let hour = date.getHours();
                let min = date.getMinutes();
                let second = date.getSeconds();
                let milSecond = date.getMilliseconds();
                div.innerHTML = year + "年"
                + (month < 10 ? "0" + month : month) + "月"
                + (monthDay < 10 ? "0" + monthDay : monthDay) + "日 周"
                + weekDay + " "
                + (hour < 10 ? "0" + hour : hour) + ":"
                + (min < 10 ? "0" + min : min)
                + ":" + (second < 10 ? "0" + second : second)
                + ":" + milSecond
            }
    </script>
</head>
<body>
<h1 id="time"></h1>
</body>
</html>